home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / biz / dbase / db.lha / Examples / Relations / unique.db < prev   
Text File  |  1995-09-27  |  940b  |  48 lines

  1. /* Make a unique ID number
  2.  * ARrexx script for db that makes a unique ID if nothing is entered in the
  3.  * current field or searches for duplicates if something IS entered.
  4.  * The script will never reuse a previously removed ID.
  5.  *
  6.  * By David Ekholm 1995 
  7.  * $VER: unique.db 1.0 (26.9.95)
  8.  *
  9.  */
  10.  
  11. Options Results
  12.  
  13. CurrentRecord
  14. newrec = result
  15.  
  16. GetField
  17. keyval = result
  18. BlockInput
  19.  
  20. if keyval ~= "" then do /* Check for duplicates */
  21.     Mode 'Find'
  22.     Kill
  23.     PutField keyval
  24.     FindFirst
  25.     if result == newrec then FindNext
  26.     matchrec = result
  27.     CurrentRecord newrec
  28.     FreeInput
  29.     if matchrec ~= newrec then do    /* This record is a duplicate */
  30.         DisplayBeep
  31.         Okay1 "There is already a record with this key!"
  32.         PutField ""
  33.         RetryInput
  34.     end
  35. end
  36. else do    /* Make a unique ID instead */
  37.     maxID = 1
  38.     FirstRecord
  39.     do while rc == 0
  40.         GetField
  41.         if result >= maxID then maxID = result + 1
  42.         NextRecord
  43.     end
  44.     CurrentRecord newrec
  45.     FreeInput
  46.     PutField maxID
  47. end
  48.